home *** CD-ROM | disk | FTP | other *** search
/ Champak 138 / Volume 138 Aug 19 2011 - Damaged.iso / Games / shadez.swf / scripts / Local / Audio / CSoundChannel.as < prev    next >
Text File  |  2011-08-19  |  8KB  |  297 lines

  1. package Local.Audio
  2. {
  3.    import Local.CGlobal;
  4.    import flash.events.Event;
  5.    import flash.events.EventDispatcher;
  6.    import flash.media.SoundChannel;
  7.    import flash.media.SoundTransform;
  8.    import flash.utils.getTimer;
  9.    
  10.    public class CSoundChannel extends EventDispatcher
  11.    {
  12.       
  13.       public static const CLOSING:String = "CLOSING";
  14.       
  15.       public static const mMixVolumeMax:Number = 1;
  16.       
  17.       public static const DISPOSING:String = "DISPOSING";
  18.       
  19.       public static const mDisturbTime:int = 1000 / 50;
  20.        
  21.       
  22.       private var mSoundChannel:SoundChannel;
  23.       
  24.       public var mSounds:Object;
  25.       
  26.       private var mNewSound:Boolean;
  27.       
  28.       private var mResumeStartPosition:int;
  29.       
  30.       public var mPauseTimeStamp:uint;
  31.       
  32.       public var mDisposed:Boolean;
  33.       
  34.       public var _StartTimeStamp:uint;
  35.       
  36.       private var mSample:CSample;
  37.       
  38.       public function CSoundChannel()
  39.       {
  40.          super();
  41.          mSounds = new Array();
  42.       }
  43.       
  44.       public function set mStartTimeStamp(param1:uint) : void
  45.       {
  46.          var _loc2_:CSound = null;
  47.          if(true)
  48.          {
  49.             _StartTimeStamp = param1;
  50.          }
  51.          for each(_loc2_ in mSounds)
  52.          {
  53.             _loc2_.mTimeStamp = _StartTimeStamp;
  54.          }
  55.       }
  56.       
  57.       public function RemoveSound(param1:CSound) : void
  58.       {
  59.          param1.removeEventListener(CSound.DISPOSING,e_SOUND_DISPOSING);
  60.          mSounds.splice(mSounds.indexOf(param1),1);
  61.          param1.Dispose();
  62.          param1.mChannel = null;
  63.          if(mSounds.length == 0)
  64.          {
  65.             Dispose();
  66.          }
  67.       }
  68.       
  69.       public function AddSound(param1:CSound) : void
  70.       {
  71.          if(true)
  72.          {
  73.             mSounds.push(param1);
  74.             if(true)
  75.             {
  76.                if(!mSample)
  77.                {
  78.                   if(true)
  79.                   {
  80.                      mSample = param1.mSample;
  81.                      addr31:
  82.                      mNewSound = true;
  83.                   }
  84.                   param1.mChannel = this;
  85.                   param1.addEventListener(CSound.DISPOSING,e_SOUND_DISPOSING);
  86.                   addr49:
  87.                   return;
  88.                   addr37:
  89.                }
  90.                ┬º┬ºgoto(addr31);
  91.             }
  92.             ┬º┬ºgoto(addr37);
  93.          }
  94.          ┬º┬ºgoto(addr49);
  95.       }
  96.       
  97.       public function get mStartTimeStamp() : uint
  98.       {
  99.          return _StartTimeStamp;
  100.       }
  101.       
  102.       public function get mSampleID() : String
  103.       {
  104.          ┬º┬ºpush(mSample);
  105.          if(true)
  106.          {
  107.             return !!┬º┬ºpop() ? mSample.mID : "none";
  108.          }
  109.          ┬º┬ºgoto(addr14);
  110.       }
  111.       
  112.       public function Start() : Boolean
  113.       {
  114.          mStartTimeStamp = getTimer();
  115.          mNewSound = false;
  116.          if(mSoundChannel = mSample.Start(mSoundTransform))
  117.          {
  118.             mSoundChannel.addEventListener(Event.SOUND_COMPLETE,e_SOUNDCOMPLETE);
  119.          }
  120.          ┬º┬ºpush(mSoundChannel == null);
  121.          if(true)
  122.          {
  123.             ┬º┬ºpush(!┬º┬ºpop());
  124.          }
  125.          return ┬º┬ºpop();
  126.       }
  127.       
  128.       public function Pause() : void
  129.       {
  130.          var _loc1_:CSound = null;
  131.          mResumeStartPosition = mSoundChannel.position;
  132.          mPauseTimeStamp = getTimer();
  133.          Stop();
  134.          for each(_loc1_ in mSounds)
  135.          {
  136.             _loc1_.Pause();
  137.          }
  138.       }
  139.       
  140.       private function e_SOUND_DISPOSING(param1:Event = null) : void
  141.       {
  142.          var _loc2_:CSound = null;
  143.          _loc2_ = CSound(param1.currentTarget);
  144.          RemoveSound(_loc2_);
  145.       }
  146.       
  147.       public function Resume() : void
  148.       {
  149.          var _loc1_:CSound = null;
  150.          for each(_loc1_ in mSounds)
  151.          {
  152.             if(true)
  153.             {
  154.                _loc1_.Resume();
  155.             }
  156.          }
  157.          if(true)
  158.          {
  159.             _StartTimeStamp += getTimer() - mPauseTimeStamp;
  160.             if(true)
  161.             {
  162.                if(mSoundChannel = mSample.Start(mSoundTransform,mResumeStartPosition))
  163.                {
  164.                   mSoundChannel.addEventListener(Event.SOUND_COMPLETE,e_SOUNDCOMPLETE);
  165.                }
  166.             }
  167.             Update();
  168.          }
  169.       }
  170.       
  171.       private function get mSoundsUpdated() : Boolean
  172.       {
  173.          if(true)
  174.          {
  175.             return !mSample.mLooping && mNewSound;
  176.          }
  177.          ┬º┬ºgoto(addr17);
  178.       }
  179.       
  180.       public function Restart() : void
  181.       {
  182.          if(true)
  183.          {
  184.             Stop();
  185.             Start();
  186.          }
  187.       }
  188.       
  189.       public function Update() : void
  190.       {
  191.          var _loc1_:CSound = null;
  192.          for each(_loc1_ in mSounds.slice())
  193.          {
  194.             _loc1_.Update();
  195.          }
  196.          if(mDisposed)
  197.          {
  198.             return;
  199.          }
  200.          if(mSoundChannel)
  201.          {
  202.             if(mSoundChannel.position > mDisturbTime && mSoundsUpdated)
  203.             {
  204.                Restart();
  205.             }
  206.             else
  207.             {
  208.                mSoundChannel.soundTransform = mSoundTransform;
  209.             }
  210.          }
  211.          else
  212.          {
  213.             Start();
  214.          }
  215.       }
  216.       
  217.       private function Stop() : void
  218.       {
  219.          if(mSoundChannel)
  220.          {
  221.             mSoundChannel.stop();
  222.             mSoundChannel.removeEventListener(Event.SOUND_COMPLETE,e_SOUNDCOMPLETE);
  223.             mSoundChannel = null;
  224.          }
  225.       }
  226.       
  227.       private function e_SOUNDCOMPLETE(param1:Event = null) : void
  228.       {
  229.          if(true)
  230.          {
  231.             dispatchEvent(new Event(CLOSING));
  232.             Dispose();
  233.          }
  234.       }
  235.       
  236.       public function get mSoundTransform() : SoundTransform
  237.       {
  238.          var _loc1_:Number = NaN;
  239.          var _loc2_:Number = NaN;
  240.          var _loc3_:Number = NaN;
  241.          var _loc4_:Number = NaN;
  242.          var _loc5_:CSound = null;
  243.          var _loc6_:SoundTransform = null;
  244.          if(!CGlobal.mSoundActive)
  245.          {
  246.             return new SoundTransform(0,0);
  247.          }
  248.          _loc1_ = 0;
  249.          _loc2_ = 0;
  250.          _loc3_ = 0;
  251.          _loc4_ = 0;
  252.          for each(_loc5_ in mSounds)
  253.          {
  254.             if(true)
  255.             {
  256.                _loc3_ += _loc5_.mSoundTransform.leftToLeft;
  257.                if(true)
  258.                {
  259.                   _loc4_ += _loc5_.mSoundTransform.rightToRight;
  260.                   if(_loc5_.mSoundTransform.volume <= _loc2_)
  261.                   {
  262.                      continue;
  263.                   }
  264.                }
  265.                _loc2_ = _loc5_.mSoundTransform.volume;
  266.             }
  267.          }
  268.          if(true)
  269.          {
  270.             (_loc6_ = !!mSoundChannel ? mSoundChannel.soundTransform : new SoundTransform()).volume = _loc2_;
  271.             if(true)
  272.             {
  273.                _loc6_.leftToLeft = _loc3_ / mSounds.length;
  274.                _loc6_.rightToRight = _loc4_ / mSounds.length;
  275.             }
  276.             return _loc6_;
  277.          }
  278.          ┬º┬ºgoto(addr98);
  279.       }
  280.       
  281.       public function Dispose() : void
  282.       {
  283.          var _loc1_:CSound = null;
  284.          dispatchEvent(new Event(DISPOSING));
  285.          Stop();
  286.          for each(_loc1_ in mSounds)
  287.          {
  288.             _loc1_.mChannel = null;
  289.          }
  290.          if(true)
  291.          {
  292.             mDisposed = true;
  293.          }
  294.       }
  295.    }
  296. }
  297.